#!/bin/bash

#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements.  See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership.  The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License.  You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
#  KIND, either express or implied.  See the License for the
# specific language governing permissions and limitations
# under the License.
#

#
# Clean a Cordova/iOS project
#

set -e

CORDOVA_PATH=$( cd "$( dirname "$0" )" && pwd -P)
PROJECT_PATH="$(dirname "$CORDOVA_PATH")"

#项目名称
# XCODEPROJ=$( ls "$PROJECT_PATH" | grep .xcodeproj  )
# PROJECT_NAME=$(basename "$XCODEPROJ" .xcodeproj)

#获取项目空间相应信息
XCWORKSPACE=$( ls "$PROJECT_PATH" | grep .xcworkspace  )
XCWORKSPACE_NAME=$(basename "$XCWORKSPACE" .xcworkspace)
SCHEME=chameleon-bundled

source "$CORDOVA_PATH/check_reqs"

cd "$PROJECT_PATH"

#下面为对工程的编译的清楚
# xcodebuild -project "$PROJECT_NAME.xcodeproj" -configuration Debug -alltargets clean
# xcodebuild -project "$PROJECT_NAME.xcodeproj" -configuration Release -alltargets clean

# 以下为对项目空间的编译的清楚
xcodebuild -workspace "$XCWORKSPACE_NAME.xcworkspace" -configuration Debug -scheme $SCHEME clean
xcodebuild -workspace "$XCWORKSPACE_NAME.xcworkspace" -configuration Release -scheme $SCHEME clean

rm -rf "build"
